package br.com.uglyboys;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import br.com.uglyboys.control.CorreioController;
import br.com.uglyboys.model.ObjetoRastreavel;

public class TelaAdd extends Activity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.exibirTelaAdd();
	}

	private void exibirTelaAdd() {
		setContentView(R.layout.tela_add);
		
		final Button  btnTick = (Button) findViewById(R.btn.btnTick);
		btnTick.setBackgroundDrawable(getResources().getDrawable(R.drawable.tick));
		btnTick.setOnFocusChangeListener(new View.OnFocusChangeListener() {
			@Override
			public void onFocusChange(View v, boolean hasFocus) {
				if(hasFocus){
					btnTick.setBackgroundDrawable(getResources().getDrawable(R.drawable.tickfocus));
				}else{
					btnTick.setBackgroundDrawable(getResources().getDrawable(R.drawable.tick));
				}
			}
		});
		btnTick.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				System.out.println("Adicionando novo objetoRastreavel");
				EditText txtCodigo = (EditText) findViewById(R.id.txtCodigo);
				EditText txtDescricao = (EditText) findViewById(R.id.txtDescricao);
				ObjetoRastreavel objetoRastreavel = new ObjetoRastreavel(txtCodigo.getText().toString(), txtDescricao.getText().toString());
				CorreioController.getInstancia().salvarObjetoRastreavel(objetoRastreavel);
				finish();
			}
		});
		
		
	}
}
